import { useGetFetchOptions, type Options } from './common'

/**
 * 请求
 * 
 * @param key 请求key
 * @param url 请求url
 * @param options 请求设置
 */
export const useHttp = async <T>(key: string, url: string, options: Options = {}) => {
    options = useGetFetchOptions(options)
    options.key = key
    const res = await $fetch<R<T>>(url, { ...options })
    return res
}
/**
 * Get请求
 * 
 * @param key 请求key
 * @param url 请求url
 * @param options 请求设置
 */
export const useFetchGet = <T>(key: string, url: string, options: Options = {}) => {
    options.method = 'GET'
    return useHttp<T>(key, url, options)
}
/**
 * Post请求
 * 
 * @param key 请求key
 * @param url 请求url
 * @param options 请求设置
 */
export const useFetchPost = <T>(key: string, url: string, options: Options = {}) => {
    options.method = 'POST'
    return useHttp<T>(key, url, options)
}